﻿using System;
using Codeflows;
using Codeflows.Dispatch;
using CodeflowsTests.Scenarios;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CodeflowsTests
{
    [TestClass]
    public class DispatcherTests
    {
		[TestInitialize]
		public void SetUp()
		{
			CodeflowApplication.SetCodeflowTrackerFactory(Tracker.InMemory);
		}

        [TestMethod]
        [ExpectedException(typeof(TimeoutException))]
        public void When_codeflow_runs_longer_than_it_should_an_exception_is_thrown()
        {
            WhenCodeflow.Executed<TimingOutCodeflow>(c => c.Start(), TimeSpan.FromMilliseconds(100));
        }

        [TestMethod]
        public void When_codeflow_requires_codeflow_id_its_correctly_populated_via_action_context()
        {
            var result = WhenCodeflow.Executed<CodeflowRequiringCodeflowId>(c => c.Start(RuntimeValues.ActionContext));
            result.ItShouldEndWithValue(result.CodeflowId);
        }
    }
}
